<template>
  <ant-modal
    modalWidth='800'
    modalHeight='500'
    :visible='open'
    :modal-title='formTitle'
    :adjust-size='true'
    @cancel='cancel'
  >
    <a-form-model ref='form' :model='form' :rules='rules' slot='content' layout='vertical'>
      <a-row :gutter='32'>
        <a-col :span='12'>
          <a-form-model-item label='供应商' prop='supplierId'>
            <a-select
              placeholder='请选择供应商'
              v-model='form.supplierId'
              :getPopupContainer='
                triggerNode => {
                  return triggerNode.parentNode || document.body
                }
              '
              style='width: 100%'
              allow-clear>
              <a-select-option v-for='(d, index) in supplierList' :key='index' :value='d.id'>{{ d.name }}
              </a-select-option>
            </a-select>
          </a-form-model-item>
        </a-col>
        <a-col :span='12'>
          <a-form-model-item label='运费' prop='shipPrice'>
            <a-input-number v-model='form.shipPrice' :min='0' style='width: 100%' />
          </a-form-model-item>
        </a-col>
        <a-col :span='12'>
          <a-form-model-item label='优惠价格' prop='discountPrice'>
            <a-input-number v-model='form.discountPrice' :min='0' style='width: 100%' />
          </a-form-model-item>
        </a-col>
        <a-col :span='24'>
          <a-form-model-item label='采购条目' prop='billItems'>
            <a-table :data-source="form.billItems" :columns="columns" :rowKey="(r,i)=>{ return i}" :pagination='false'>
              <template slot="materialId" slot-scope="text, record">
                <a-select placeholder="请选择原材料" v-model="record.materialId" allow-clear>
                  <a-select-option v-for="(d, index) in materialList" :key="index" :value="d.id">{{ d.name }}</a-select-option>
                </a-select>
              </template>
              <template slot="price" slot-scope="text, record">
                <a-input-number v-model="record.price" :min="0" />
              </template>
              <template slot="count" slot-scope="text, record">
                <a-input-number v-model="record.count" :min="0" />
              </template>
              <template slot="action" slot-scope="text, record">
                <a-icon type='delete' @click='removeItem(record)'/>
              </template>
            </a-table>
          </a-form-model-item>
        </a-col>
        <a-col :span='24'>
          <a-form-item>
            <a-button type='dashed' block @click='addItem'>
              <a-icon type='plus' />
              增加条目
            </a-button>
          </a-form-item>
        </a-col>
        <a-col :span='24'>
          <a-form-model-item label='备注' prop='remark'>
            <a-textarea v-model='form.remark' placeholder='请输入备注' :rows='4' />
          </a-form-model-item>
        </a-col>
      </a-row>
    </a-form-model>
    <template slot='footer'>
      <a-button :disabled='disabled' @click='cancel'>
        取消
      </a-button>
      <a-button type='primary' :disabled='disabled' @click='submitForm(true)'>
        保存
      </a-button>
    </template>
  </ant-modal>
</template>
<script>
import TinaBillAddForm from './TinaBillForm'

export default {
  ...TinaBillAddForm
}
</script>
